package br.com.zorandir.importacoes;

import java.util.Calendar;
import java.util.Map;

import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.unsafe.batchinsert.BatchInserter;
import org.neo4j.unsafe.batchinsert.BatchInserters;

import br.com.zorandir.relacionamento.Relacionamentos;

public class Importador {
	public static void main(String[] args) {
		Importador importador = new Importador();
		BatchInserter inserter = BatchInserters.inserter("database");

		System.out.println("Importa dados");

		importador.importaPessoas(inserter);
		importador.importaProdutos(inserter);
		importador.importaCategoria(inserter);

		importador.importaVisualizacoes(inserter);
		importador.importaCompras(inserter);
		importador.importaDentro(inserter);

		inserter.shutdown();
		System.out.println("Fim da importação");
	}

	private void importaDentro(BatchInserter inserter) {
		long hora = Calendar.getInstance().getTimeInMillis();

		// Eletronicos
		inserter.createRelationship(7, 22, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(8, 22, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(9, 22, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(10, 22, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(11, 22, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(12, 22, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(13, 22, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		
		// Livros
		inserter.createRelationship(14, 23, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(15, 23, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(16, 23, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(17, 23, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		
		// Músicas
		inserter.createRelationship(18, 24, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(19, 24, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(20, 24, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
		inserter.createRelationship(21, 24, Relacionamentos.DENTRO_DE, MapUtil.map("cadastrado em", hora));
	}

	private void importaCategoria(BatchInserter inserter) {
		Map<String, Object> eletronico = MapUtil.map("nome", "Eletronico");
		Map<String, Object> livro = MapUtil.map("nome", "Livro");
		// Map<String, Object> filme = MapUtil.map("tipo_categoria", "Filme");
		Map<String, Object> musica = MapUtil.map("nome", "Musica");

		inserter.createNode(22, eletronico);
		inserter.createNode(23, livro);
		// inserter.createNode(24, filme);
		inserter.createNode(24, musica);

	}

	private void importaCompras(BatchInserter inserter) {
		inserter.createRelationship(1, 12, Relacionamentos.COMPROU, MapUtil.map("valor", 800.00));
		inserter.createRelationship(1, 16, Relacionamentos.COMPROU, MapUtil.map("valor", 59.90));
		inserter.createRelationship(1, 18, Relacionamentos.COMPROU, MapUtil.map("valor", 40.00));
		inserter.createRelationship(2, 7, Relacionamentos.COMPROU, MapUtil.map("valor", 350.00));
		inserter.createRelationship(2, 11, Relacionamentos.COMPROU, MapUtil.map("valor", 2000.00));
		inserter.createRelationship(2, 14, Relacionamentos.COMPROU, MapUtil.map("valor", 99.00));
		inserter.createRelationship(3, 21, Relacionamentos.COMPROU, MapUtil.map("valor", 65.00));
		inserter.createRelationship(3, 17, Relacionamentos.COMPROU, MapUtil.map("valor", 40.00));
		inserter.createRelationship(4, 9, Relacionamentos.COMPROU, MapUtil.map("valor", 1800.00));
		inserter.createRelationship(4, 21, Relacionamentos.COMPROU, MapUtil.map("valor", 55.00));
		inserter.createRelationship(4, 19, Relacionamentos.COMPROU, MapUtil.map("valor", 45.00));
		inserter.createRelationship(5, 15, Relacionamentos.COMPROU, MapUtil.map("valor", 1800.00));

	}

	private void importaProdutos(BatchInserter inserter) {
		Map<String, Object> galaxy5 = MapUtil.map("nome", "Galaxy 5", "tipo", "Android");
		Map<String, Object> nokia = MapUtil.map("nome", "Nokia", "tipo", "Symbian");
		Map<String, Object> galaxyS2 = MapUtil.map("nome", "Galaxy S2", "tipo", "Android");
		Map<String, Object> galaxyS3 = MapUtil.map("nome", "Galaxy S3", "tipo", "Android");
		Map<String, Object> iPhone4S = MapUtil.map("nome", "iPhone 4S", "tipo", "IOS");
		Map<String, Object> blackBerry = MapUtil.map("nome", "BlackBerry", "tipo", "BlackBerry");
		Map<String, Object> iPhone5 = MapUtil.map("nome", "iPhone 5", "tipo", "Android");

		Map<String, Object> dracula = MapUtil.map("nome", "Dracula", "tipo", "Terror");
		Map<String, Object> david_lachapelle = MapUtil.map("nome", "David LaChapelle", "tipo", "Arte"); // fic��o
		Map<String, Object> frankenstein = MapUtil.map("nome", "Frankenstein", "tipo", "Terror");
		Map<String, Object> banksy = MapUtil.map("nome", "Banksy", "tipo", "Arte");
		
		Map<String, Object> metallica_live = MapUtil.map("nome", "Metallica Live", "tipo", "Rock");
		Map<String, Object> the_black_keys = MapUtil.map("nome", "The Black Keys-Brother", "tipo", "Blues/Rock"); // fic��o
		Map<String, Object> florence = MapUtil.map("nome", "Florence and the machine", "tipo", "Indie");
		Map<String, Object> foo_fighters = MapUtil.map("nome", "Foo Fighters", "tipo", "Rock");

		inserter.createNode(7, galaxy5);
		inserter.createNode(8, nokia);
		inserter.createNode(9, galaxyS2);
		inserter.createNode(10, galaxyS3);
		inserter.createNode(11, iPhone4S);
		inserter.createNode(12, blackBerry);
		inserter.createNode(13, iPhone5);
		
		inserter.createNode(14, dracula);
		inserter.createNode(15, david_lachapelle);
		inserter.createNode(16, frankenstein);
		
		inserter.createNode(17, banksy);

		inserter.createNode(18, metallica_live);
		inserter.createNode(19, the_black_keys);
		inserter.createNode(20, florence);
		inserter.createNode(21, foo_fighters);
	}

	private void importaVisualizacoes(BatchInserter inserter) {
		long hora = Calendar.getInstance().getTimeInMillis();

		inserter.createRelationship(1, 11, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(1, 21, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(1, 14, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(2, 8, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(2, 10, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(2, 21, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(3, 8, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(3, 16, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(4, 12, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(4, 13, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(5, 10, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(5, 13, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(5, 20, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(6, 12, Relacionamentos.COMPROU, MapUtil.map("em", hora));
		inserter.createRelationship(6, 19, Relacionamentos.COMPROU, MapUtil.map("em", hora));
	}

	private void importaPessoas(BatchInserter inserter) {
		Map<String, Object> joao = MapUtil.map("nome", "Joao");
		Map<String, Object> ricardo = MapUtil.map("nome", "Ricardo");
		Map<String, Object> carolina = MapUtil.map("nome", "Carolina");
		Map<String, Object> maria = MapUtil.map("nome", "Maria");
		Map<String, Object> fernando = MapUtil.map("nome", "Fernando");
		Map<String, Object> fabio = MapUtil.map("nome", "Fabio");

		inserter.createNode(1, joao);
		inserter.createNode(2, ricardo);
		inserter.createNode(3, carolina);
		inserter.createNode(4, maria);
		inserter.createNode(5, fernando);
		inserter.createNode(6, fabio);
	}
}